package com.easyaop.api.spring;

import com.easyaop.api.around.Around;
import com.easyaop.api.join.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class ToAspectJ {

    private final Around around;

    public Object invoke(ProceedingJoinPoint joinPoint) throws Exception {
        Object target = joinPoint.getThis();
        Object[] args = joinPoint.getArgs();
        JoinPoint ajJoinPoint = JoinPoint.of(target.getClass(), "1212112");

        return around.around(target, args, ajJoinPoint, () -> {
            try {
                return joinPoint.proceed();
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        });
    }
}
